#include <cairo.h>  
#include <gtk/gtk.h>  
   
   
gboolean timer = TRUE;  
cairo_surface_t *image;  
   
   
static gboolean  
on_expose_event(GtkWidget *widget,  
    GdkEventExpose *event,  
    gpointer data)  
{  
  cairo_t *cr;  
  cairo_t *ic;  
   
  cairo_surface_t *surface;  
   
  static gdouble angle = 0;  
  static gint image_width = 0;  
  static gint image_height = 0;  
   
  static gint w = 0;  
  static gint h = 0;  
  
  /* 从窗口创建一个cairo环境 */
  cr = gdk_cairo_create(widget->window);  
   
  gint width, height;  
  gtk_window_get_size(GTK_WINDOW(widget), &width, &height);  
   
  image_width = cairo_image_surface_get_width(image);  
  image_height = cairo_image_surface_get_height(image);  
  w = image_width;  
   
  /* 创建剪切板的面和环境 */
  surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, image_width, image_height);  
  ic = cairo_create(surface);  
  /* 在剪切板上绘制矩形，宽w, 高h */
  cairo_rectangle(ic, 0, 0, w, h);  
  cairo_fill(ic);  
   
  h += 1;  
  if( h == image_height) timer = FALSE;  
   
  /* 设置源图片 */
  cairo_set_source_surface(cr, image, 0, 0);  
  /* 设置遮盖（蒙版） */
  cairo_mask_surface(cr, surface, 0, 0);  
   
  /* 释放申请的资源 */
  cairo_surface_destroy(surface);  
  cairo_destroy(cr);  
  cairo_destroy(ic);  
  return FALSE;  
}  
   
static gboolean  
time_handler(GtkWidget *widget)  
{  
  if(widget->window == NULL) return FALSE;  
   
  if(!timer) return FALSE;  
   
  gtk_widget_queue_draw(widget);  
  return TRUE;  
}  
   
int main(int argc,char *argv[])  
{  
  GtkWidget *window;  
  gint width, height;
  /* 加载图片 */
  image = cairo_image_surface_create_from_png("../assert/back.png");  
  width = cairo_image_surface_get_width(image);
  height = cairo_image_surface_get_height(image);
  gtk_init(&argc, &argv);  
   
  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);  
   
  g_signal_connect(G_OBJECT(window),"expose-event",  
      G_CALLBACK(on_expose_event), NULL);  
  g_signal_connect(G_OBJECT(window),"destroy",  
      G_CALLBACK(gtk_main_quit), NULL);  
   
  gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);  
  gtk_window_set_default_size(GTK_WINDOW(window), width, height);  
  gtk_window_set_title(GTK_WINDOW(window),"blind down");  
   
  gtk_widget_set_app_paintable(window, TRUE);  
  g_timeout_add(15, (GSourceFunc) time_handler, (gpointer) window);  
   
  gtk_widget_show_all(window);  
   
  gtk_main();  
   
  cairo_surface_destroy(image);  
   
  return 0;  
}  